package com;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bean.Shop;
import com.dao.SomeFun;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.sql.Array;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/s1")
public class Select1 extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws IOException {
        //设置请求乱码
        req.setCharacterEncoding("utf-8");
        //设置响应乱码
        resp.setContentType("text/html;charset=utf-8");
        String keyword = req.getParameter("keyword");
        List<Shop> shops = new ArrayList<>();
        if (keyword==null &&"".equals(keyword)){
            resp.getWriter().write(JSONObject.toJSONString(shops));
        }else {
            SomeFun someFun = new SomeFun();
            try {
                shops = someFun.selectlike(keyword);
            } catch (ClassNotFoundException e) {
                e.printStackTrace();
            } catch (SQLException e) {
                e.printStackTrace();
            }
            resp.getWriter().write(JSONObject.toJSONString(shops));


        }
    }
}
